package com.tiantianyuegou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tiantianyuegou.R;
import com.tiantianyuegou.model.GuanModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/7.
 */
public class GuanListAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;
    private List<GuanModel> mData;

    public GuanListAdapter(Context context) {
        this.context = context;
        mData = new ArrayList<>();
        inflater = LayoutInflater.from(context);
    }

    public GuanListAdapter(Context context, List<GuanModel> listGuan) {
        this.context = context;
        this.mData = listGuan;
        inflater = LayoutInflater.from(context);
    }

    public void setData(List<GuanModel> data) {
        mData.clear();
        mData.addAll(data);
    }


    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.item_list_guan, viewGroup,false);
            holder = new ViewHolder();
            holder.text_operation = (TextView) view.findViewById(R.id.text_operation);
            holder.text_data = (TextView) view.findViewById(R.id.text_data);
            holder.text_guan_num = (TextView) view.findViewById(R.id.text_guan_num);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        String g = mData.get(i).getTgrType() + "";
        if (g.equals("1")) {
            holder.text_operation.setText("订单交易抵扣");
            holder.text_guan_num.setTextColor(context.getResources().getColor(R.color.textcolor_red));
            holder.text_guan_num.setText(mData.get(i).getTgrCount()+"");
        } else if (g.equals("2")) {
            holder.text_operation.setText("纯贯购");
            holder.text_guan_num.setTextColor(context.getResources().getColor(R.color.textcolor_red));
            holder.text_guan_num.setText(mData.get(i).getTgrCount()+"");
        } else if (g.equals("3")) {
            holder.text_operation.setText("分享");
            holder.text_guan_num.setTextColor(context.getResources().getColor(R.color.green_normal));
            holder.text_guan_num.setText("+"+mData.get(i).getTgrCount());
        } else if (g.equals("4")) {
            holder.text_operation.setText("注册");
            holder.text_guan_num.setTextColor(context.getResources().getColor(R.color.green_normal));
            holder.text_guan_num.setText("+"+mData.get(i).getTgrCount()+"");
        } else if (g.equals("5")) {
            holder.text_operation.setText("加盟店铺");
            holder.text_guan_num.setTextColor(context.getResources().getColor(R.color.green_normal));
            holder.text_guan_num.setText("+"+mData.get(i).getTgrCount()+"");
        } else if (g.equals("6")) {
            holder.text_operation.setText("买家消费");
            holder.text_guan_num.setTextColor(context.getResources().getColor(R.color.textcolor_red));
            holder.text_guan_num.setText(mData.get(i).getTgrCount()+"");
        } else if (g.equals("7")) {
            holder.text_operation.setText("刷新商品");
        }
        holder.text_data.setText(mData.get(i).getTgrAddTime());
        return view;
    }

    public static class ViewHolder {
        TextView text_guan_num, text_operation, text_data, text_order;
    }
}
